package com.allwees.core.common.i18n;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * 代码中需要国际化后返回给前端展示的信息、字段
 * @author Daniel
 * @version 1.0.0
 * @since 2020/12/16 15:09
 */
@Data
@Component
@ConfigurationProperties(prefix = "msg")
@PropertySource(value = "classpath:/i18nMsg.properties", encoding = "UTF-8")
public class I18nMessage {

    @Value("${spring.profiles.active}")
    private String profile;

    public String getCodPayError() {
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getCodPayError).orElse("Pay Error");
    }

    public String getOrderWaitShipMsg() {
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getWaitShipMsg).orElse("Waiting For Shipment");
    }

    public String getOrderShippingMsg() {
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getShippingMsg).orElse("Shipping");
    }

    public String getOrderCancelMsg() {
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getCancelMsg).orElse("Canceled");
    }

    public String getRefundDesc() {
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getRefundDesc).orElse("User proactively refund");
    }

    public String getHotSellName(){
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getHotSellName).orElse("Popular");
    }

    public String getConfirmTitle(){
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getOrderConfirmEmailTitle).orElse("Your Allwees Order Confirmation");
    }

    public String getWelcomeTitle(){
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getWelcomeEmailTitle).orElse("Welcome to Allwees!");
    }

    public String getJoionTitle(){
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getJoinEmailTitle).orElse("Thank you for joining Allwees");
    }

    public String getForotPwdTitle(){
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getFogotPwdEmailTitle).orElse("Allwees password reset");
    }

    public String getVerifyEmailTitle(){
        return Optional.ofNullable(getSiteMessage()).map(SiteMessage::getVerifyEmailTitle).orElse("Please verify your Email");
    }

    private SiteMessage ae;
    private SiteMessage sa;

    private SiteMessage getSiteMessage() {
        if ("ae".equals(profile) || "aen".equals(profile)) {
            return ae;
        }

        if ("sa".equals(profile) || "san".equals(profile)) {
            return sa;
        }
        return null;
    }

    @Data
    public static class SiteMessage {
        private String codPayError;
        private String waitShipMsg;
        private String shippingMsg;
        private String cancelMsg;
        private String refundDesc;
        private String hotSellName;
        private String orderConfirmEmailTitle;
        private String welcomeEmailTitle;
        private String joinEmailTitle;
        private String fogotPwdEmailTitle;
        private String verifyEmailTitle;
    }
}